/*
 * Copyright 2013 Agustina Martinez-Garcia

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 */
package uk.ljmu.qudexapps.swfspreadsheet.actions;

import java.io.File;
import java.io.FileInputStream;
//import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.StringWriter;
import java.io.Writer;

import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerConfigurationException;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.stream.StreamResult;
import javax.xml.transform.stream.StreamSource;

//import org.dom4j.DocumentException;

public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		//Class loader to load the XSLT file
		ClassLoader classLoader = Thread.currentThread()
		.getContextClassLoader();
		InputStream is = classLoader.getResourceAsStream("ddi-transform.xslt");
		Source xslSource = null;
		try {
		    TransformerFactory  tFactory =
		        TransformerFactory.newInstance();
		    xslSource = new StreamSource(is);
		    Transformer transformer = tFactory.newTransformer(xslSource);
		    Writer outWriter = new StringWriter();  
		    StreamResult result = new StreamResult( outWriter );
		    String fullPath = "/Users/amg857/Desktop/2000esds.xml";
		    FileInputStream fileIs = new FileInputStream(new File(fullPath));
		    transformer.transform(new StreamSource(fileIs), result);
		    StringWriter sw = (StringWriter) result.getWriter();
		    System.out.println(sw);
		} catch (TransformerConfigurationException e) {
		    
		} catch (TransformerException e) {
		    
		} finally {
		    if (is != null)
		    	is.close();
		}

	}

}
